# rules.mk for xparser
# by lxb

ALL_OBJS = $(XP_OBJS)

CC = gcc -c
LINK = gcc
AR = ar
CFLAGS = -g -O0 -fno-builtin -fno-strict-aliasing -Wall -Werror
LINKFLAGS = $(LINKFLAGS_CMDLINE) -g
FSMGEN = python ../tools/xpgenfsm.py
FSMDEF_HEADER = $(FSMDEF).h
OBJ_DIR=.objs

INCLS = -I../include -I.

ifeq "$(OS_ARCH)" "Linux"
	MACROS := -DOS_LINUX=1
endif
ifeq "$(OS_ARCH)" "WIN"
	MACROS := -DOS_WIN=1
endif

nop: all

#---------------------------------
# Executable
#---------------------------------
.PHONY: exeout
exeout: $(OBJ_DIR) $(FSMDEF_HEADER) $(ALL_OBJS) 
	$(LINK) $(LINKFLAGS) $(addprefix $(OBJ_DIR)/, $(ALL_OBJS)) -o $(XPARSER)

libout: $(FSMDEF_HEADER) $(ALL_OBJS)
	$(AR) rucs libxparser.a $(addprefix $(OBJ_DIR)/, $(ALL_OBJS))
#---------------------------------
# pattern rules
#---------------------------------

$(OBJ_DIR): 
	mkdir $@
	
%.o: %.c
	@echo "Compiling $< ..."	
	$(CC) $(CFLAGS) $(INCLS) $(MACROS) -c -o $(OBJ_DIR)/$@ $<

%_fsm.h: %_fsm.conf
	$(FSMGEN) $< > $@
#---------------------------------
# clean rules
#---------------------------------
.PHONY: clobj
clobj: 
	rm -r -f $(OBJ_DIR)

#---------------------------------
# debug rules
#---------------------------------
.PHONY: show
show: 
	echo $(FSMDEF_HEADER)



